/**
 * @summary 文章请求模块
 */
import req from '@/utils/request';
import * as URL from '@/constants/api';

/**
 * @param { string } articleId
 * @returns
 * @summary 获取文章评论列表
 */
export function getArticleCommentList(articleId) {
  return req({
    url: URL.COMMENT,
    params: {
      type: 'a',
      source: articleId,
    },
  })
    .then((res) => res.data.data)
    .catch(() => null);
}

/**
 * @param { string } articleId 文章id
 * @param { string } commentContent 评论内容
 * @returns
 * @summary 对文章发表评论
 */
export function publicArticleComment(articleId, commentContent) {
  return req({
    url: URL.COMMENT,
    method: 'post',
    data: {
      target: articleId,
      content: commentContent,
      art_id: null,
    },
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}
